package com.kn.common.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author zhouxp
 * @create 2021-01-20 10:07
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class R {
    private Integer code;
    private String msg;
    private Object data;

    public static R ok(RCode rCode,Object data){
        return new R(rCode.getCode(),rCode.getMsg(),data);
    }
    public static R ok(RCode rCode){
        return new R(rCode.getCode(),rCode.getMsg(),null);
    }
    public static R ok(Object data){
        return  R.ok(RCode.SUCCESS,data);
    }
    public static R ok(){
        return  R.ok(RCode.SUCCESS,null);
    }

    public static R error(RCode rCode){
        return  new R(rCode.getCode(),rCode.getMsg(),null);
    }
    public static R error(){
        return   R.error(RCode.SYS_ERROR);
    }
    public static R error(String msg){
        return   new R(RCode.SYS_ERROR.getCode(),msg,null);
    }
}
